#include<bits/stdc++.h>
using namespace std;
long long t,n,arr[200005],before[200005],anss[200005],ans,adans;
void solve(){
    map<long long,long long> mp;
    adans=ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];
    int j=0;
    for(int i=1;i<=n;i++){
        if(arr[i]==arr[i-1])adans+=arr[i];
        else j++;
        arr[j]=arr[i];
    //    if(t==4&&arr[i]>10) cout<<arr[i]<<" ";
    }
    n=j;
    for(int i=1;i<=n;i++){
        before[i]=mp[arr[i]];
        mp[arr[i]]=i;
    }
    for(int i=1;i<=n;i++){
        if(before[i]==0)anss[i]=anss[i-1];
        else anss[i]=max(anss[i-1],anss[before[i]+1]+arr[i]);
        ans=max(ans,anss[i]);
       // if(i%10000==0) cout<<ans<<"!!!\n";
    }
    cout<<ans+adans<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>t;
    while(t--) solve();
    fclose(stdin);
    fclose(stdout);
	return 0;
}
